package jmine.tec.report.impl.table.pdf;

import java.text.SimpleDateFormat;
import java.util.Date;

import jmine.tec.report.api.table.ReportCell;
import jmine.tec.report.impl.table.RendererParameterInterface;
import jmine.tec.report.impl.table.ReportTableBuilder;

import com.lowagie.text.Element;

/**
 * @author finx
 * @created Apr 20, 2010
 */
public class TimestampCellPDFRenderer extends AbstractCellPDFRenderer {

    private static final String PATTERN_DEFAULT_TIMESTAMP = "dd/MM/yyyy HH:mm:ss";

    /**
     * {@inheritDoc}
     */
    public String getRendererType() {
        return ReportTableBuilder.TYPE_TIMESTAMP;
    }

    /**
     * {@inheritDoc}
     */
    public String getFormattedString(ReportCell cell) {
        if (cell.getValue() == null) {
            return "";
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_DEFAULT_TIMESTAMP);
            return sdf.format(Date.class.cast(cell.getValue()));
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected int getHorizontalAlignment(RendererParameterInterface rpi) {
        return Element.ALIGN_CENTER;
    }

}
